package lanqiao.demo;

import java.math.BigInteger;
import java.util.Scanner;

/**
 * 最大公约数和最小公倍数
 *  1.利用辗转相除法
 *  2.欧几里得算法
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int t = func(x, y);
        System.out.println("最大公约数:" + t);
        System.out.println("最小公倍数:" + (x * y) / t);
        System.out.println("=============================");
        BigInteger tt = gcd(new BigInteger(x + ""), new BigInteger(y + ""));
        System.out.println("最大公约数:" + tt);
        System.out.println("最小公倍数:" + (new BigInteger(x + "").multiply(new BigInteger(y + ""))).divide(tt));
    }

    private static int func(int a, int b) {
        if (a < b) {
            int t = a;
            a = b;
            b = t;
        }
        while (a % b != 0) {
            int t = a % b;
            a = b;
            b = t;
        }
        return b;
    }

    public static BigInteger gcd(BigInteger a, BigInteger b){
        if (b.compareTo(BigInteger.ZERO)==0){
           return a;
        }
        return gcd(b,a.mod(b));

    }
}
